***Last Updated: 11/04/2021 Stata17
/*==========================================*
Paper:			Trade-offs? The Impact of WTO Accession on Intimate Partner Violence in Cambodia

Purpose:        Generate figures using import tariff and census data

To re-run our analysis, please install a folder "Cambodia". There should be 4 subfolders in order for do-files to run:

"created"
"do files"
"graphs"
"output"

/***********************************/
/* INDEX:                          */
/* FIGURE 1                        */
/* APPENDIX FIGURE A1               */
/* APPENDIX FIGURE A2               */
/***********************************/

*==========================================*/

clear
set more off 
set matsize 8000
cap log close

global dir="XXX\Cambodia"
cd "$dir"

log using "Log_figures.log", replace

global grfont "Georgia"

***************************************************************************************
**FIGURE 1: RELATIONSHIP BETWEEN TARIFF CHANGES AND PRELIBERALIZATION TARIFF LEVELS 
***************************************************************************************
use "created/tariffs_3digit.dta", clear

gen tariff_1=tariff/100
keep if partner==0
keep if year==2001 |year==2014
sort code year
drop if code==231 //code==231 only has no data for 2014
drop if code==401|code==402 //no data in either 2001 or 2014
gen dtariff = tariff_1 - tariff_1[_n-1]
gen tariff_change=dtariff[_n+1]
keep if year==2001
drop dtariff
rename tariff_1 tariff_rate

label var tariff_rate "2001 preliberalization tariff rate"
label var tariff_change "2001-2014 change in tariff"

*Drop industries that do not exist in 1998 Census data:
drop if code==101|code==111|code==152|code==173|code==182|code==233|code==241 ///
|code==243|code==252|code==272|code==291|code==293|code==300|code==311|code==312 ///
|code==313|code==319|code==321|code==331|code==332|code==333|code==341|code==342 ///
|code==351|code==352|code==353

save "graphs/tariff_change.dta", replace

gen shortcode_name=""
replace shortcode_name="Crops" if code==11
replace shortcode_name="Livestock" if code==12
replace shortcode_name="Forestry" if code==20
replace shortcode_name="Fishing" if code==50
replace shortcode_name="Quarrying" if code==141
replace shortcode_name="Mining" if code==142
replace shortcode_name="Meat" if code==151
replace shortcode_name="Grain mill products" if code==153
replace shortcode_name="Food" if code==154
replace shortcode_name="Beverages" if code==155
replace shortcode_name="Tobacco" if code==160
replace shortcode_name="Textiles" if code==171
replace shortcode_name="Other textiles" if code==172
replace shortcode_name="Wearing apparel" if code==181
replace shortcode_name="Leather processing" if code==191
replace shortcode_name="Footwear" if code==192
replace shortcode_name="Wood planting" if code==201
replace shortcode_name="Wood products" if code==202
replace shortcode_name="Paper" if code==210
replace shortcode_name="Publishing" if code==221
replace shortcode_name="Printing" if code==222
replace shortcode_name="Petrolum products" if code==232
replace shortcode_name="Other chemicals" if code==242
replace shortcode_name="Rubber" if code==251
replace shortcode_name="Glass" if code==261
replace shortcode_name="Non-metallic mineral" if code==269
replace shortcode_name="Iron,steel" if code==271
replace shortcode_name="Structural metal" if code==281
replace shortcode_name="Other metal" if code==289
replace shortcode_name="Special machinery" if code==292
replace shortcode_name="Batteries" if code==314
replace shortcode_name="Lighting equipment" if code==315
replace shortcode_name="Radio transmitters" if code==322
replace shortcode_name="Radio receivers" if code==323
replace shortcode_name="Vehicle accessories" if code==343
replace shortcode_name="Transport equipment" if code==359 
replace shortcode_name="Furniture" if code==361
replace shortcode_name="Other manufacturing" if code==369

**Merge two points on scatterplot to improve readability
**Start the new code number from 401
**Code==292,261
local plus1 = _N + 1
set obs `plus1'
replace code=401 if code==. 
replace tariff_rate=(0.1458+0.1412)/2 if tariff_rate==.
replace tariff_change=(-0.0568-0.0585)/2 if tariff_change==.
replace shortcode_name="Machinery,glass" if shortcode_name==""
drop if code==292 | code==261

**Code==141,281
local plus1 = _N + 1
set obs `plus1'
replace code=402 if code==. 
replace tariff_rate=(0.0934+0.1038)/2 if tariff_rate==.
replace tariff_change=(-0.0457-0.0339)/2 if tariff_change==.
replace shortcode_name="Rock,metal" if shortcode_name==""
drop if code==141 | code==281 

**Code==242,269
local plus1 = _N + 1
set obs `plus1'
replace code=404 if code==. 
replace tariff_rate=(0.01305+0.1097)/2 if tariff_rate==.
replace tariff_change=(-0.0567-0.0461)/2 if tariff_change==.
replace shortcode_name="Chemicals,minerals" if shortcode_name==""
drop if code==242 | code==269

**Code==20,142
local plus1 = _N + 1
set obs `plus1'
replace code=406 if code==. 
replace tariff_rate=(0.1731+0.1597)/2 if tariff_rate==.
replace tariff_change=(-0.0774-0.0723)/2 if tariff_change==.
replace shortcode_name="Forestry,mining" if shortcode_name==""
drop if code==20 | code==142

**Code==12,151
local plus1 = _N + 1
set obs `plus1'
replace code=407 if code==. 
replace tariff_rate=(0.1981+0.2343)/2 if tariff_rate==.
replace tariff_change=(-0.0874-0.0926)/2 if tariff_change==.
replace shortcode_name="Livestock,meat" if shortcode_name==""
drop if code==12 | code==151

**Code==154,160
local plus1 = _N + 1
set obs `plus1'
replace code=409 if code==. 
replace tariff_rate=(0.1822+0.1712)/2 if tariff_rate==.
replace tariff_change=(-0.0787-0.0821)/2 if tariff_change==.
replace shortcode_name="Other food,tobacco" if shortcode_name==""
drop if code==154 | code==160

gen position=3
replace position=9 if tariff<10 | code==322 | code==251 |code==314 | code==160
replace position=9 if code==202 | code==172 | code==191 |code==192 
replace position=9 if code==201 | code==369 | code==153 | code==289 | code==171
replace position=9 if code==404 | code==402 | code==405
replace position=10 if code==315 
replace position=6 if code==141 
replace position=2 if code==20 | code==401
replace position=2 if code==403 | code==406
replace position=1 if code==343 |code==359
replace position=11 if code==142 | code==405 
replace position=4 if code==11 | code==151 
replace position=8 if code==289
replace position=3 if code==271|code==222

twoway scatter  tariff_change tariff_rate, msize(small) mlabel(shortcode_name) mlabsize(small) mlabvposition(position) mlabcolor(black) ytitle("2001-2014 change in tariff rate") ylabel(0(-0.05)-0.3, angle(0) format(%04.2f)) xlabel(0(0.1)0.4, angle(0) format(%04.2f)) graphregion(color(white)) plotregion(margin(l+10 r+10)) ///
      || lfit tariff_change tariff_rate, legend(off) graphregion(color(white))


graph save "graphs\Figure1", replace
graph export "graphs\Figure1.eps", replace font($grfont)

**FIGURE A1: UNWEIGHTED AVERAGE NOMINAL TARIFF RATES
**All goods
use "originals/tariff data/tariffs_3digit.dta", clear
gen tariff_1=tariff/100
keep if partner==0
drop if code==401
collapse tariff_1, by(year)
rename tariff_1 tariff_all

label var tariff_all "All goods"

keep if year<2015

tsset year

tsline tariff_all, ytitle("Unweighted average tariff rate") xtitle("") ylabel(0.08(0.025)0.18, angle(0) format(%04.2f)) xlabel(2001(2)2014) scheme(s2mono) graphregion(color(white))
graph export "graphs\FigureA1.eps", replace font($grfont) 

***********************************************************************************
**FIGURE A2: RELATIONSHIP BETWEEN TARIFF CHANGES, FEMALE INTENSITY, AND SKILL INTENSITY OF EMPLOYMENT
***********************************************************************************
**PANEL A: RELATIONSHIP BETWEEN TARIFF CHANGES AND FEMALE SHARE OF EMPLOYMENT
use "created/census_for_analysis.dta", clear
global wt ="[aw=perwt]"
keep if year==1998
collapse (sum) employed $wt, by(sector female)
bysort sector: egen total_emp=total(employed)
gen female_share=employed/total_emp if female==1
keep if female==1
drop female employed 
save "created/female_share.dta", replace

use "graphs/tariff_change.dta", clear

gen sector=.
replace sector=1 if code==11 
replace sector=2 if code==12 
replace sector=3 if code==13 
replace sector=4 if code==14 
replace sector=5 if code==20 
replace sector=6 if code==50 
replace sector=7 if code==141 
replace sector=8 if code==142 
replace sector=9 if code==151 
replace sector=10 if code==153 
replace sector=11 if code==154 
replace sector=12 if code==155 
replace sector=13 if code==160 
replace sector=14 if code==171 
replace sector=15 if code==172 
replace sector=16 if code==181 
replace sector=17 if code==191 
replace sector=18 if code==192 
replace sector=19 if code==201 
replace sector=20 if code==202 
replace sector=21 if code==210 
replace sector=22 if code==221 
replace sector=23 if code==222 
replace sector=24 if code==232 
replace sector=25 if code==242 
replace sector=26 if code==251 
replace sector=27 if code==261 
replace sector=28 if code==269 
replace sector=29 if code==271 
replace sector=30 if code==281 
replace sector=31 if code==289 
replace sector=32 if code==292  
replace sector=33 if code==314 
replace sector=34 if code==315 
replace sector=35 if code==322 
replace sector=36 if code==323 
replace sector=37 if code==343 
replace sector=38 if code==359 
replace sector=39 if code==361 
replace sector=40 if code==369 

merge 1:1 sector using "created/female_share.dta"
drop if _m==2
drop _m

gen shortcode_name=""
replace shortcode_name="Crops" if code==11
replace shortcode_name="Livestock" if code==12
replace shortcode_name="Mixed farming" if code==13
replace shortcode_name="Animal husbandry" if code==14
replace shortcode_name="Forestry" if code==20
replace shortcode_name="Fishing" if code==50
replace shortcode_name="Quarrying" if code==141
replace shortcode_name="Mining" if code==142
replace shortcode_name="Meat" if code==151
replace shortcode_name="Grain mill products" if code==153
replace shortcode_name="Food" if code==154
replace shortcode_name="Beverages" if code==155
replace shortcode_name="Tobacco" if code==160
replace shortcode_name="Textiles" if code==171
replace shortcode_name="Other textiles" if code==172
replace shortcode_name="Wearing apparel" if code==181
replace shortcode_name="Leather processing" if code==191
replace shortcode_name="Footwear" if code==192
replace shortcode_name="Wood planting" if code==201
replace shortcode_name="Wood products" if code==202
replace shortcode_name="Paper" if code==210
replace shortcode_name="Publishing" if code==221
replace shortcode_name="Printing" if code==222
replace shortcode_name="Petrolum" if code==232
replace shortcode_name="Other chemicals" if code==242
replace shortcode_name="Rubber" if code==251
replace shortcode_name="Glass" if code==261
replace shortcode_name="Non-metallic mineral" if code==269
replace shortcode_name="Iron,steel" if code==271
replace shortcode_name="Structural metal" if code==281
replace shortcode_name="Other metal" if code==289
replace shortcode_name="Special machinery" if code==292
replace shortcode_name="Batteries" if code==314
replace shortcode_name="Lighting equip." if code==315
replace shortcode_name="Radio transmitters" if code==322
replace shortcode_name="Radio receivers" if code==323
replace shortcode_name="Vehicle accessories" if code==343
replace shortcode_name="Transport equipment" if code==359 
replace shortcode_name="Furniture" if code==361
replace shortcode_name="Other manufacturing" if code==369

**Merge two points on scatterplot to improve readability
**Start the new code number from 401
**Code==292,261
local plus1 = _N + 1
set obs `plus1'
replace code=401 if code==. 
replace female_share=(.4423077+.1975807)/2 if female_share==.
replace tariff_change=(-0.0568-0.0585)/2 if tariff_change==.
replace shortcode_name="Machinery,glass" if shortcode_name==""
drop if code==292 | code==261


**Code==141,281
local plus1 = _N + 1
set obs `plus1'
replace code=402 if code==. 
replace female_share=(.4117647+.1538462)/2 if female_share==.
replace tariff_change=(-0.0457-0.0339)/2 if tariff_change==.
replace shortcode_name="Rock,metal" if shortcode_name==""
drop if code==141 | code==281 


**Code==242,269
local plus1 = _N + 1
set obs `plus1'
replace code=404 if code==. 
replace female_share=(.15+.420438)/2 if female_share==.
replace tariff_change=(-0.0567-0.0461)/2 if tariff_change==.
replace shortcode_name="Chemicals,minerals" if shortcode_name==""
drop if code==242 | code==269

**Code==20,142
local plus1 = _N + 1
set obs `plus1'
replace code=406 if code==. 
replace female_share=(.2970297+.3906977)/2 if female_share==.
replace tariff_change=(-0.0774-0.0723)/2 if tariff_change==.
replace shortcode_name="Forestry" if shortcode_name==""
drop if code==20 | code==142

**Code==12,151
local plus1 = _N + 1
set obs `plus1'
replace code=407 if code==. 
replace female_share=(.4949349+.4622426)/2 if female_share==.
replace tariff_change=(-0.0874-0.0926)/2 if tariff_change==.
replace shortcode_name="Livestock,meat" if shortcode_name==""
drop if code==12 | code==151

**Code==154,160
local plus1 = _N + 1
set obs `plus1'
replace code=409 if code==. 
replace female_share=(.496+.5561798)/2 if female_share==.
replace tariff_change=(-0.0787-0.0821)/2 if tariff_change==.
replace shortcode_name="Other food,tobacco" if shortcode_name==""
drop if code==154 | code==160

gen position=3
replace position=9 if tariff<10 | code==251 |code==314 | code==160 | code==181
replace position=9 if code==202 | code==172 | code==191 |code==192 
replace position=9 if code==201 | code==369 | code==153 | code==289 | code==171
replace position=9 if code==404 | code==405
replace position=10 if code==315 
replace position=6 if code==141 
replace position=2 if code==20 | code==401 |code==359 |code==222 |code==315 |code==271
replace position=2 if code==403 
replace position=1 if code==343 
replace position=11 if code==142 | code==405 
replace position=4 if code==11 | code==151 |code==361
replace position=8 if code==289 | code==322 
replace position=3 if code==271 |code==210 |code==221 |code==192

twoway scatter  tariff_change female_share, msize(tiny) mlabel(shortcode_name) mlabsize(small) ///
		mlabvposition(position) mlabcolor(black) xtitle("1998 female share of employment") ///
		ytitle("2001-2014 change in tariff rate") ylabel(0(-0.05)-0.3, angle(0) format(%04.2f)) ///
		title("Panel A: Tariff reductions and pre-liberalization female share", size(4) color(black)) ///
		xlabel(, angle(0) format(%04.2f)) graphregion(color(white)) plotregion(margin(l+12 r+10 t+10))  ysize(4) xsize(6)  ///
      || lfit tariff_change female_share, legend(off) graphregion(color(white))
	 
graph save "graphs/FigureA2_PanelA", replace


**PANEL B: RELATIONSHIP BETWEEN TARIFF CHANGES AND SKILLED SHARE OF EMPLOYMENT
use "created/census_for_analysis.dta", clear
global wt ="[aw=perwt]"
keep if year==1998
collapse (sum) employed $wt, by(sector skilled)
bysort sector: egen total_emp=total(employed)
gen skilled_share=employed/total_emp if skilled==1
keep if skilled==1
drop skilled employed 
save "created/skilled_share.dta", replace

use "graphs/tariff_change.dta", clear

*Drop industries that do not exist in 1998 Census data:
drop if code==101|code==111|code==152|code==173|code==182|code==233|code==241 ///
|code==243|code==252|code==272|code==291|code==293|code==300|code==311|code==312 ///
|code==313|code==319|code==321|code==331|code==332|code==333|code==341|code==342 ///
|code==351|code==352|code==353

gen sector=.
replace sector=1 if code==11 
replace sector=2 if code==12 
replace sector=3 if code==13 
replace sector=4 if code==14 
replace sector=5 if code==20 
replace sector=6 if code==50 
replace sector=7 if code==141 
replace sector=8 if code==142 
replace sector=9 if code==151 
replace sector=10 if code==153 
replace sector=11 if code==154 
replace sector=12 if code==155 
replace sector=13 if code==160 
replace sector=14 if code==171 
replace sector=15 if code==172 
replace sector=16 if code==181 
replace sector=17 if code==191 
replace sector=18 if code==192 
replace sector=19 if code==201 
replace sector=20 if code==202 
replace sector=21 if code==210 
replace sector=22 if code==221 
replace sector=23 if code==222 
replace sector=24 if code==232 
replace sector=25 if code==242 
replace sector=26 if code==251 
replace sector=27 if code==261 
replace sector=28 if code==269 
replace sector=29 if code==271 
replace sector=30 if code==281 
replace sector=31 if code==289 
replace sector=32 if code==292  
replace sector=33 if code==314 
replace sector=34 if code==315 
replace sector=35 if code==322 
replace sector=36 if code==323 
replace sector=37 if code==343 
replace sector=38 if code==359 
replace sector=39 if code==361 
replace sector=40 if code==369 

merge 1:1 sector using "created/skilled_share.dta"
replace skilled_share=0 if _m==1
drop if _m==2
drop _m

gen shortcode_name=""
replace shortcode_name="Crops" if code==11
replace shortcode_name="Livestock" if code==12
replace shortcode_name="Forestry" if code==20
replace shortcode_name="Fishing" if code==50
replace shortcode_name="Quarrying" if code==141
replace shortcode_name="Mining" if code==142
replace shortcode_name="Meat" if code==151
replace shortcode_name="Grain mill products" if code==153
replace shortcode_name="Food" if code==154
replace shortcode_name="Beverages" if code==155
replace shortcode_name="Tobacco" if code==160
replace shortcode_name="Textiles" if code==171
replace shortcode_name="Other textiles" if code==172
replace shortcode_name="Wearing apparel" if code==181
replace shortcode_name="Leather processing" if code==191
replace shortcode_name="Footwear" if code==192
replace shortcode_name="Wood planting" if code==201
replace shortcode_name="Wood products" if code==202
replace shortcode_name="Paper" if code==210
replace shortcode_name="Publishing" if code==221
replace shortcode_name="Printing" if code==222
replace shortcode_name="Petrolum products" if code==232
replace shortcode_name="Other chemicals" if code==242
replace shortcode_name="Rubber" if code==251
replace shortcode_name="Glass" if code==261
replace shortcode_name="Non-metallic mineral" if code==269
replace shortcode_name="Iron,steel" if code==271
replace shortcode_name="Structural metal" if code==281
replace shortcode_name="Other metal" if code==289
replace shortcode_name="Special machinery" if code==292
replace shortcode_name="Batteries" if code==314
replace shortcode_name="Lighting equipment" if code==315
replace shortcode_name="Radio transmitters" if code==322
replace shortcode_name="Radio receivers" if code==323
replace shortcode_name="Vehicle accessories" if code==343
replace shortcode_name="Transport equipment" if code==359 
replace shortcode_name="Furniture" if code==361
replace shortcode_name="Other manufacturing" if code==369

**Merge two points on scatterplot to improve readability
**Start the new code number from 401
**Code==292,261
local plus1 = _N + 1
set obs `plus1'
replace code=401 if code==. 
replace skilled_share=(.088+.0609756)/2 if skilled_share==.
replace tariff_change=(-0.0568-0.0585)/2 if tariff_change==.
replace shortcode_name="Machinery,glass" if shortcode_name==""
drop if code==292 | code==261


**Code==141,281
local plus1 = _N + 1
set obs `plus1'
replace code=402 if code==. 
replace skilled_share=(.0196078+0)/2 if skilled_share==.
replace tariff_change=(-0.0457-0.0339)/2 if tariff_change==.
replace shortcode_name="Rock,metal" if shortcode_name==""
drop if code==141 | code==281 


**Code==242,269
local plus1 = _N + 1
set obs `plus1'
replace code=404 if code==. 
replace skilled_share=(.125+.0175182)/2 if skilled_share==.
replace tariff_change=(-0.0567-0.0461)/2 if tariff_change==.
replace shortcode_name="Chemicals" if shortcode_name==""
drop if code==242 | code==269

**Code==20,142
local plus1 = _N + 1
set obs `plus1'
replace code=406 if code==. 
replace skilled_share=(.0181518+.0162791)/2 if skilled_share==.
replace tariff_change=(-0.0774-0.0723)/2 if tariff_change==.
replace shortcode_name="Forestry" if shortcode_name==""
drop if code==20 | code==142

**Code==12,151
local plus1 = _N + 1
set obs `plus1'
replace code=407 if code==. 
replace skilled_share=(.0173661+.0160183)/2 if skilled_share==.
replace tariff_change=(-0.0874-0.0926)/2 if tariff_change==.
replace shortcode_name="Livestock,meat" if shortcode_name==""
drop if code==12 | code==151

**Code==154,160
local plus1 = _N + 1
set obs `plus1'
replace code=409 if code==. 
replace skilled_share=(.016+.0786517)/2 if skilled_share==.
replace tariff_change=(-0.0787-0.0821)/2 if tariff_change==.
replace shortcode_name="Other food,tobacco" if shortcode_name==""
drop if code==154 | code==160

gen position=3
replace position=9 if tariff<10 | code==251 |code==314 | code==160 | code==181
replace position=9 if code==202 | code==172 | code==191 |code==192 |code==50
replace position=9 if code==201 | code==369 | code==153 | code==289 
replace position=9 if code==404 | code==405
replace position=10 if code==315 
replace position=6 if code==141 
replace position=2 if code==20 | code==401 |code==359 |code==222 |code==315 |code==271
replace position=2 if code==403 |code==409
replace position=1 if code==343 
replace position=11 if code==142 | code==405 
replace position=4 if code==11 | code==151 |code==323
replace position=8 if code==289  |code==407
replace position=3 if code==210 |code==221 |code==171 |code==251

twoway scatter  tariff_change skilled_share, msize(tiny) mlabel(shortcode_name) mlabsize(small)  ///
		mlabvposition(position) mlabcolor(black) xtitle("1998 skilled share of employment") /// 
		ytitle("2001-2014 change in tariff rate") ylabel(0(-0.05)-0.3, angle(0) format(%04.2f)) ///
		title("Panel B: Tariff reductions and pre-liberalization skilled share", size(4) color(black)) ///
		xlabel(, angle(0) format(%04.2f)) graphregion(color(white)) plotregion(margin(l+12 r+10 t+10)) ysize(4) xsize(6) ///
      || lfit tariff_change skilled_share, legend(off) graphregion(color(white))
	  
graph save "graphs/FigureA2_PanelB", replace

graph combine "graphs/FigureA2_PanelA.gph" "graphs/FigureA2_PanelB", col(1) graphregion(color(white) lcolor(white) lwidth(thick)) ///
	ysize(9) xsize(6) title("", size(3.5) color(black)) saving("graphs/FigureA2.gph", replace)

graph export "graphs/FigureA2.eps", replace font($grfont)

log close
